package com.kaishengit.service;

import java.util.List;

import com.kaishengit.dao.SingleFileDao;
import com.kaishengit.entity.SingleFile;
import com.kaishengit.entity.UserProject;
import com.kaishengit.util.DateUtil;
import com.kaishengit.util.PkUtil;
import com.kaishengit.util.SizeUtil;

public class SingleFileService {
		SingleFileDao  sfDao=new SingleFileDao();
	public List<SingleFile> FindByFileTypeId(String FileTypeId){
		sfDao.findByFileTypeId(FileTypeId);
		return  sfDao.findByFileTypeId(FileTypeId);
	}
	 public SingleFile findByFilename (String filename){
		return sfDao.findByFilename(filename);

	}
	 public void del (String id){
		 sfDao.del(id);
		 
	 }
		
		public void save(String name, String newName, long size,
				String filetypeid, UserProject userProject) {
			SingleFile  sf=new SingleFile();
			sf.setSize(SizeUtil.readableFileSize(size));
			sf.setName(name);
			sf.setCreate_time(DateUtil.getNowDateTime());
			sf.setFilename(newName);
			sf.setCreate_time(DateUtil.getNowDateTime());
			sf.setId(PkUtil.getId());
			sf.setUser(userProject.getUser());
			sf.setUserId(userProject.getUser().getId());
			sf.setFileTypeId(filetypeid);
		
			sfDao.save(sf);
			
		}
		
	
}
